import Component from './Component'
import {wrapToVdom} from './utils';

/**
 *
 * @param type 元素类型
 * @param config 配置对象
 * @param children 儿子或儿子们
 */
function createElement(type, config, children) {
  let ref,key;
  if (config) {
    delete config.__source;
    delete config.__self;
    //↑ 这俩源码里用到了 我们暂时用不到 先删除

    ref = config.ref;
    delete config.ref;

    key = config.key;
    delete config.key;
  }

  const props = {...config};
  if (arguments.length > 3) {
    // eslint-disable-next-line prefer-rest-params
    children = Array.prototype.slice.call(arguments, 2);
  }
  props.children = Array.isArray(children)?children.map(wrapToVdom):wrapToVdom(children); //所以... children可能是数组 也可能是个 独生子(对象)

  return {
    type,
    ref, //ref不在props里
    key, //key也不在props里
    props
  }
}

function createRef(){
  return {current: null};
}

const React = {createElement,Component,createRef}

export default React;
